define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'xilumarket/discover/topic_forum/index' + location.search,
                    add_url: 'xilumarket/discover/topic_forum/add',
                    edit_url: 'xilumarket/discover/topic_forum/edit',
                    del_url: 'xilumarket/discover/topic_forum/del',
                    multi_url: 'xilumarket/discover/topic_forum/multi',
                    dragsort_url:'',
                    table: 'xilumarket_topic_forum',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                fixedColumns: true,
                fixedRightNumber: 1,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User_id'),operate: "LIKE"},
                        {field: 'topic_id', title: __('Topic_id'), searchList: Config.topicLists, formatter: Table.api.formatter.normal},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'status', title: __('Status'),yes:'normal',no:'hidden', searchList: {"hidden":__('Status hidden'),"normal":__('Status normal')}, formatter: Table.api.formatter.status},
                        {field: 'hot_status', title: __('Hot_status'), searchList: {"0":__('Hot_status 0'),"1":__('Hot_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'check_status', title: __('Check_status'), searchList: {"1":__('Check_status 1'),"2":__('Check_status 2'),"3":__('Check_status 3')}, formatter: Table.api.formatter.status},
                        {field: 'fav_count', title: __('Fav_count'),operate: false},
                        {field: 'share_count', title: __('Share_count'),operate: false},
                        {field: 'comment_count', title: __('Comment_count'),operate: false},
                        {field: 'collection_count', title: __('Collection_count'),operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
